package com.weitu.environmental.monitor.service.impl;

import com.weitu.environmental.monitor.entity.MonitorPoint;
import com.weitu.environmental.monitor.mapper.MonitorPointAndProjectMapper;
import com.weitu.environmental.monitor.mapper.MonitorPointMapper;
import com.weitu.environmental.monitor.service.MonitorPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-03-31
 */
@Service
public class MonitorPointServiceImpl implements MonitorPointService {

    private final MonitorPointMapper monitorPointMapper;
    private final MonitorPointAndProjectMapper monitorPointAndProjectMapper;

    @Autowired
    public MonitorPointServiceImpl(MonitorPointMapper monitorPointMapper, MonitorPointAndProjectMapper monitorPointAndProjectMapper) {
        this.monitorPointMapper = monitorPointMapper;
        this.monitorPointAndProjectMapper = monitorPointAndProjectMapper;
    }

    @Override
    public List<MonitorPoint> findByParam(Map paramMap) {
        return monitorPointMapper.findByParam(paramMap);
    }


    @Override
    public Integer findByParamCount(Map paramMap) {
        return monitorPointMapper.findByParamCount(paramMap);
    }

    @Override
    public MonitorPoint findById(String id) {
        return monitorPointMapper.findById(id);
    }

    @Transactional
    @Override
    public Integer add(List monitorProjectList,Map pointMap) {

        if(monitorProjectList.size()>0){
            monitorPointAndProjectMapper.add(monitorProjectList);
        }

        return monitorPointMapper.add(pointMap);
    }

    @Transactional
    @Override
    public Integer updateById(List monitorProjectList,Map paramMap,String pointId) {
        if(monitorProjectList.size()>0){
            monitorPointAndProjectMapper.deleteByPointId(pointId);
            monitorPointAndProjectMapper.add(monitorProjectList);
        }

        return monitorPointMapper.updateById(paramMap);
    }

    @Override
    public Integer deleteById(Map paramMap) {
        return monitorPointMapper.updateById(paramMap);
    }


}
